Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Max Consecutive Ones III (medium)
Problem Statement
Given an array nums containing 1 and 0 digits, return the maximum number of consecutive 1s if you can flip at most any k 0s.
Examples
-
Example 1:
- Input: nums =
[1, 0, 1, 1, 0, 0, 1, 1, 1, 0], k =2 - Expected Output:
7 - Justification: Flipping the two 0s in the middle section
[0, 0]results in the longest continuous sequence of 1s:[1, 1, 1, 1, 1, 1, 1].
- Input: nums =
-
Example 2:
- Input: nums =
[0, 1, 1, 0, 1, 0, 1, 0, 1], k =1 - Expected Output:
4 - Justification: Flipping the
0at index 3 will yield a maximum continuous sequence of four 1s.
- Input: nums =
-
Example 3:
- Input: nums =
[1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1], k =3 - Expected Output:
8 - Justification: Flipping the three 0s in the middle
[0, 0, 0]results in the longest sequence of 1s:[1, 1, 1, 1, 1, 1, 1, 1].
- Input: nums =
Constraints:
- 1 <= nums.length <= 105
- nums[i] is either 0 or 1.
- 0 <= k <= nums.length
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Dot Product of Two Sparse Vectors
Solution: Max Consecutive Ones III
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself